#ifndef __MESSAGEPUMP
#define __MESSAGEPUMP

#include "Message.h"
#include <stdlib.h>
#pragma warning(disable: 4786)
#include <list>
#include <map>


class  Message;
struct MessageReg;
struct MessageType;
class ICallback;

typedef std::list<Message*> MessageList;
typedef std::map<int,MessageType*> MessageTypeMap;


class MessagePump 
{
public:
    static inline MessagePump* Instance()
    {
        static MessagePump inst;
        return &inst;
    }
    
    static void Update(int dt);
    static void AddMessageToSystem(int type);
    static  int RegisterForMessage(int flag, int type, void* parent, int objectID, ICallback& cBack);
    static void UnRegisterForMessage(int flag, int type, int objectID);
    static void UnRegisterAll(int flag, int objectID);
    static void SendMsg(Message* newMessage);
    static char* GetMessageName(int type);

protected:
	static void DeliverMsg(Message* pMsg);
	static void BroadcastMsg(Message* pMsg, MessageType* pMsgType);
	static void UnicastMsg(Message* pMsg, MessageType* pMsgType);

protected:
    MessagePump();
    MessagePump& operator= (const MessagePump&){}

protected:
    static MessageTypeMap m_messageTypes;
    static MessageList    m_messageQueue;
    static MessageList    m_messageIncomingQueue;
};

#define s_MessagePump MessagePump::Instance() 

#endif